package com.ycsj.goldmedalnewconcept.activity;

import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.utils.Validator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;


/**
 * 创建日期：2017/11/7  17:46
 * 描述:红包验证界面
 * 作者:张伟
 */

@SuppressLint("NewApi")
public class RedVerifyActivity extends Activity implements View.OnClickListener {

    private LinearLayout llBack;
    private EditText etTel;
    private Button btYz;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_red_verify);
        setBar();
        initView();
        initListener();
    }

    /**
     * 设置监听的方法
     */
    private void initListener() {
        llBack.setOnClickListener(this);
        btYz.setOnClickListener(this);
    }

    /**
     * 初始化View的方法
     */
    private void initView() {
        llBack = (LinearLayout) findViewById(R.id.ll_back);
        etTel = (EditText) findViewById(R.id.et_tel);
        btYz = (Button) findViewById(R.id.bt_cx);
    }


    /**
     * 点击事件
     *
     * @param view
     */
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_back:
                finish();
                break;
            case R.id.bt_cx:
                //判断手机号码的正确性
                judge();
                break;
        }

    }

    /**
     * 判断手机号码的正确性进行跳转
     */
    private void judge() {
        String tel = etTel.getText().toString().trim();
        if (TextUtils.isEmpty(tel)) {
            Toast.makeText(this, "请输入手机号码", Toast.LENGTH_SHORT).show();
            return;
        }

        if (!Validator.isMobile(tel)) {
            Toast.makeText(this, "手机号码格式不正确", Toast.LENGTH_SHORT).show();
            return;
        }

        Intent intent = new Intent(this, RedPacListActivity.class);
        intent.putExtra("tel", tel);
        startActivity(intent);

    }

    /**
     * 设置沉浸状态栏的方法,需要在setContentView()之后调用
     */
    private void setBar() {
        //兼容5.0+，状态栏设置透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        } else
            //为了沉浸式状态栏 4.4以上才有
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
    }


}
